package com.soft.springhrms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.soft.springhrms.pojo.Salaries;
import com.soft.springhrms.service.SalariesService;
import com.soft.springhrms.mapper.SalariesMapper;
import com.soft.springhrms.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author DELL
 * @description 针对表【salaries】的数据库操作Service实现
 * @createDate 2024-11-16 18:48:18
 */
@Service
public class SalariesServiceImpl extends ServiceImpl<SalariesMapper, Salaries> implements SalariesService {
    @Autowired
    private SalariesMapper salariesMapper;

    @Override
    public ResultVO querySalariesById(Integer id, int pageNum, int pageSize) {
        QueryWrapper<Salaries> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("employee_id", id);
        Page<Salaries> page = new Page<>(pageNum, pageSize);
        // 执行分页查询
        IPage<Salaries> resultPage = salariesMapper.selectPage(page, queryWrapper);
        // 判断结果是否为空
        if (resultPage.getRecords().isEmpty()) {
            return ResultVO.success(resultPage, "暂无数据");
        }
        // 直接使用查询结果，不需要手动复制
        return ResultVO.success(resultPage, "查询成功");
    }

    @Override
    public ResultVO queryAllSalaries(int pageNum, int pageSize) {
        QueryWrapper<Salaries> queryWrapper = new QueryWrapper<>();
        Page<Salaries> page = new Page<>(pageNum, pageSize);
        // 执行分页查询
        IPage<Salaries> resultPage = salariesMapper.selectPage(page, null);
        // 判断结果是否为空
        if (resultPage.getRecords().isEmpty()) {
            return ResultVO.success(resultPage, "暂无数据");
        }
        // 直接使用查询结果，不需要手动复制
        return ResultVO.success(resultPage, "查询成功");
    }

    @Override
    public ResultVO updateSalaries(Salaries salaries) {
        int rows = salariesMapper.updateById(salaries);
        if (rows > 0) {
            return ResultVO.success("审批成功");
        } else {
            return ResultVO.error(404, "未找到对应请求记录");
        }
    }

}




